package com.excuse.excusebuilder.presenter;

import android.content.Context;
import android.text.TextUtils;

import com.excuse.excusebuilder.base.IBaseList;
import com.excuse.excusebuilder.base.IBaseView;
import com.excuse.excusebuilder.base.ToastSaveListener;
import com.excuse.excusebuilder.bean.Option;
import com.excuse.excusebuilder.bean.Result;
import com.excuse.excusebuilder.bean.Type;
import com.excuse.excusebuilder.commen.util.MyToast;

/**
 * Created by 鹏君 on 2017/4/19.
 */

public class AddOptionActivityPresenter {
    private Context context;
    private IView activity;

    public AddOptionActivityPresenter(Context context, IView activity) {
        this.context = context;
        this.activity = activity;
    }

    public void addOption(Type type, String optionStr, final String resultStr) {
        if (TextUtils.isEmpty(optionStr) || TextUtils.isEmpty(resultStr)) {
            MyToast.showToast(context, "请输入完整信息");
            return;
        }
        activity.showLoading(true);
        final Option option = new Option(type, optionStr);
        option.save(new ToastSaveListener<String>(context, activity) {
            @Override
            public void onSuccess(String s) {
                Result result = new Result(option, resultStr);
                result.save(new ToastSaveListener<String>(context, activity) {
                    @Override
                    public void onSuccess(String s) {
                        activity.showLoading(false);
                        MyToast.showToast(context, "已添加");
                        activity.finish();
                    }
                });
            }
        });
    }

    public interface IView extends IBaseList {

    }
}
